﻿using ShoppingCar.carousel;
using ShoppingCar.Carousels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace ShoppingCar
{
    public class CarouselsAppService : ApplicationService, ICarouselsService
    {
        private readonly IRepository<Carousel, int> _Carousel;

        public CarouselsAppService(IRepository<Carousel, int> carousels)
        {

            _Carousel = carousels;
        }
        //添加
        public int CreateButtom(CreateUpdateCarouselsDto dto)
        {
            var add = new Carousel()
            {
                CarouselName = dto.CarouselName,
                CarouselUrl = dto.CarouselUrl,
                CarouselOrder = dto.CarouselOrder,
                Carouselstate = dto.Carouselstate
            };
            _Carousel.InsertAsync(add);
            return 10;
        }
        //删除
        public int DeleteCarousels(int id)
        {
            _Carousel.DeleteAsync(id);
            return 10; 
        }
        //反填
        public CarouselsDto Fantian(int id)
        {
            Carousel bottom = _Carousel.Where(s => s.Id.Equals(id)).FirstOrDefault();
            return ObjectMapper.Map<Carousel, CarouselsDto>(bottom);
        }
        //显示
        public List<CarouselsListDto> GetButtomLists()
        {
            var get = from a in _Carousel
                      select new CarouselsListDto
                      {
                          Id = a.Id,
                          CarouselName = a.CarouselName,
                          CarouselUrl = a.CarouselUrl,
                          CarouselOrder = a.CarouselOrder,
                          Carouselstate = a.Carouselstate
                      };
            var list = get.ToList();
            return list;
        }
        //修改
        public int UpdateCarousel(int id, CreateUpdateCarouselsDto dto)
        {
            Carousel headss = _Carousel.FirstOrDefault(s => s.Id.Equals(id));
            headss.CarouselName = dto.CarouselName;
            headss.CarouselUrl = dto.CarouselUrl;
            headss.CarouselOrder = dto.CarouselOrder;
            headss.Carouselstate = dto.Carouselstate;
            _Carousel.UpdateAsync(headss);
            return 10;
        }
        //状态按钮修改
        public CarouselsDto UpdateState(int id)
        {
            Carousel bottom1 = _Carousel.FirstOrDefault(s => s.Id.Equals(id));
            if (bottom1.Carouselstate == 1)
            {
                bottom1.Carouselstate = 0;
            }
            else
            {
                bottom1.Carouselstate = 1;
            }
            return ObjectMapper.Map<Carousel, CarouselsDto>(bottom1);
        }
    }
}
